Skip to content

@computed fields from mixin types (with) cause column does not exist error when the model is explicitly included#2539

Open
lsmith77 wants to merge 1 commit intozenstackhq:devfrom
lsmith77:computed-field-nested-include.test
Open

@computed fields from mixin types (with) cause column does not exist error when the model is explicitly included#2539
lsmith77 wants to merge 1 commit intozenstackhq:devfrom
lsmith77:computed-field-nested-include.test

Conversation

@lsmith77
Copy link
Copy Markdown
Contributor

@lsmith77 lsmith77 commented Mar 31, 2026

failing test to illustrate #2540 along with a one line fix

Summary by CodeRabbit

  • Tests

    • Added an end-to-end Vitest verifying computed fields inherited from a mixin are populated on child records both when queried directly and when returned via a parent query with nested includes.
  • Bug Fix

    • Broadened computed-field detection so inherited/aggregated computed fields are surfaced correctly, preventing missing computed values for nested includes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Vitest e2e test for a mixin-inherited computed field and updates the TypeScript schema generator to include computed fields from all discovered fields (including mixins) when emitting computedFields.

Changes

Cohort / File(s) Summary
E2E Test: computed-field nested include
tests/e2e/orm/client-api/computed-field-nested-include.test.ts
Adds a Vitest e2e test that defines a ParentRelated mixin with a nullable computed field parentCode, Parent and Child models, creates sample data, and asserts Child.parentCode is populated both when querying children directly and when children are returned via Parent with include: { children: true }.
Schema generator: computed field detection
packages/sdk/src/ts-schema-generator.ts
Modifies TsSchemaGenerator.createDataModelObject to derive computedFields from allFields (via getAllFields(dm)) instead of only dm.fields, allowing computed fields inherited through mixins to be emitted in the schema.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 I hopped through fields and schema trees,
Mixins whispered codes on every breeze,
Parents include children, no column lost,
Tests now dance without runtime cost,
Nibbling carrots — CI passes with ease 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main issue being fixed: @computed fields from mixin types causing column-does-not-exist errors in explicit includes, which aligns with the test case and code fix in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/e2e/orm/client-api/computed-field-nested-include.test.ts (1)

60-60: Prefer typed validation over as any to maintain type-safety in this regression test.

Line 60 suppresses compiler checks that could catch future API/schema drift. The options object should use satisfies to validate against the function signature while preserving flexibility with string schemas:

♻️ Suggested refactor
-            } as any,
+            } satisfies Parameters<typeof createTestClient>[1],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/orm/client-api/computed-field-nested-include.test.ts` at line 60,
The test currently uses an unsafe cast ("as any") for the options object;
replace that cast with TypeScript's "satisfies" operator to validate the object
against the real API parameter type (for example the parameter type of the
client function under test, e.g. Parameters<typeof <clientFunction>>[0] or the
exported options type from the API), so the literal keeps flexible string-schema
values but still gets compile-time validation; locate the options object in
computed-field-nested-include.test.ts and change the "as any" to a "satisfies
<expected parameter type>" check (import or reference the appropriate
function/type used by the test).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/orm/client-api/computed-field-nested-include.test.ts`:
- Line 60: The test currently uses an unsafe cast ("as any") for the options
object; replace that cast with TypeScript's "satisfies" operator to validate the
object against the real API parameter type (for example the parameter type of
the client function under test, e.g. Parameters<typeof <clientFunction>>[0] or
the exported options type from the API), so the literal keeps flexible
string-schema values but still gets compile-time validation; locate the options
object in computed-field-nested-include.test.ts and change the "as any" to a
"satisfies <expected parameter type>" check (import or reference the appropriate
function/type used by the test).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3260908e-0086-4ab1-91a3-d57d0a4b7523

📥 Commits

Reviewing files that changed from the base of the PR and between 80f364a and 9e94d09.

📒 Files selected for processing (1)
  • tests/e2e/orm/client-api/computed-field-nested-include.test.ts

@lsmith77 lsmith77 force-pushed the computed-field-nested-include.test branch from 9e94d09 to 2abea97 Compare April 1, 2026 18:16
@lsmith77 lsmith77 force-pushed the computed-field-nested-include.test branch 2 times, most recently from 0653d1d to 397146d Compare April 9, 2026 09:15
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/sdk/src/ts-schema-generator.ts (1)

456-456: Reuse allFields instead of calling getAllFields(dm) twice.

This avoids a second recursive walk and keeps field selection logic centralized.

♻️ Suggested cleanup
-        const computedFields = getAllFields(dm).filter((f) => hasAttribute(f, '@computed'));
+        const computedFields = allFields.filter((f) => hasAttribute(f, '@computed'));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sdk/src/ts-schema-generator.ts` at line 456, The code calls
getAllFields(dm) again when computing computedFields causing an extra recursive
walk; instead reuse the existing allFields array (the variable already holding
getAllFields(dm) results) and filter that for hasAttribute(f, '@computed') so
computedFields = allFields.filter(f => hasAttribute(f, '@computed')); update the
reference to use allFields and remove the duplicate getAllFields(dm) call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/sdk/src/ts-schema-generator.ts`:
- Line 456: The code calls getAllFields(dm) again when computing computedFields
causing an extra recursive walk; instead reuse the existing allFields array (the
variable already holding getAllFields(dm) results) and filter that for
hasAttribute(f, '@computed') so computedFields = allFields.filter(f =>
hasAttribute(f, '@computed')); update the reference to use allFields and remove
the duplicate getAllFields(dm) call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7231e313-2b0c-4e75-a446-41409eea847c

📥 Commits

Reviewing files that changed from the base of the PR and between 0653d1d and 397146d.

📒 Files selected for processing (2)
  • packages/sdk/src/ts-schema-generator.ts
  • tests/e2e/orm/client-api/computed-field-nested-include.test.ts

@lsmith77 lsmith77 force-pushed the computed-field-nested-include.test branch from 397146d to adc753f Compare April 9, 2026 09:38
@lsmith77 lsmith77 force-pushed the computed-field-nested-include.test branch from adc753f to afc9d44 Compare April 9, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant